trigger LeadConversion on Lead (after update) {
	List<School_Funding_Application__c> sfaToInsert=new List<School_Funding_Application__c>();
	List<id> idsTargeted=new List<id>();
	List<Opportunity> oppToDelete=new List<Opportunity>();
	//Select s.Total_Classes__c, s.SystemModstamp, s.Stage__c, s.Space_for_Kitchen_Dining__c, s.Space_for_Garden__c, s.School__c, s.Relationship_with_School__c, s.Relationship_Other__c, s.Principal_s_Last_Name__c, s.Principal_s_First_Name__c, s.OwnerId, s.Name, s.Main_Contact__c, s.LastModifiedDate, s.LastModifiedById, s.LastActivityDate, s.IsDeleted, s.Id, s.Funding_Round__c, s.Financial_Capacity_to_Support__c, s.Existing_Kitchen__c, s.Existing_Garden__c, s.Date_Awarded__c, s.CreatedDate, s.CreatedById, s.Community_Connections__c, s.Amount_Requested__c, s.Amount_Awarded__c From School_Funding_Application__c s
	for(Lead l : Trigger.new){
		if(l.isConverted&&l.Enquiry_Type__c=='Expression of Interest'){
			School_Funding_Application__c sfa = new School_Funding_Application__c(Principal_s_First_Name__c=l.Principal_s_First_Name__c, Principal_s_Last_Name__c=l.Principal_s_Last_Name__c, Existing_Kitchen__c=l.Existing_Kitchen__c, Existing_Garden__c=l.Existing_Garden__c, Space_for_Kitchen_Dining__c=l.Space_for_Kitchen_Dining__c, Space_for_Garden__c=l.Space_for_Garden__c, Financial_Capacity_to_Support__c=l.Financial_Capacity_to_Support__c, Community_Connections__c=l.Community_Connections__c, Total_Classes__c=l.Total_Classes__c, Main_Contact__c=l.ConvertedContactId, School__c=l.ConvertedAccountId, Stage__c='Interested');
			sfaToInsert.add(sfa);
			idsTargeted.add(l.ConvertedOpportunityId);
		}
	}
	if(!sfaToInsert.isEmpty())
	{	insert sfaToInsert;
	}
	if(!idsTargeted.isEmpty()){
		oppToDelete=[select id from Opportunity where id IN :idsTargeted];
		if(!oppToDelete.isEmpty())
		{	delete oppToDelete;
		}
	}
}